package com.ssy.lingxi.marketing.serviceimpl;

import com.ssy.lingxi.common.constant.marketing.ActivityTypeEnum;
import com.ssy.lingxi.common.constant.marketing.BelongTypeEnum;
import com.ssy.lingxi.common.constant.member.MemberRoleEnum;
import com.ssy.lingxi.common.exception.BusinessException;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.marketing.entity.activity.ActivityGoodsDO;
import com.ssy.lingxi.marketing.entity.activity.PlatformActivityDO;
import com.ssy.lingxi.marketing.entity.activity.PlatformActivityInviteDO;
import com.ssy.lingxi.marketing.entity.activity.PlatformActivitySignUpDO;
import com.ssy.lingxi.marketing.model.bo.PfActivitySignUpPageBO;
import com.ssy.lingxi.marketing.model.constant.*;
import com.ssy.lingxi.marketing.model.vo.activity.request.*;
import com.ssy.lingxi.marketing.model.vo.activity.response.*;
import com.ssy.lingxi.marketing.model.vo.common.response.TaskStepVO;
import com.ssy.lingxi.marketing.model.vo.coupon.request.FilterSkuIdRequest;
import com.ssy.lingxi.marketing.model.vo.coupon.request.FilterSkuIdResponse;
import com.ssy.lingxi.marketing.repository.ActivityGoodsRepository;
import com.ssy.lingxi.marketing.repository.PlatformActivityRepository;
import com.ssy.lingxi.marketing.repository.PlatformActivitySignUpRepository;
import com.ssy.lingxi.marketing.service.IPlatformActivitySignUpService;
import com.ssy.lingxi.marketing.service.IProcessFeignService;
import com.ssy.lingxi.marketing.serviceimpl.base.activity.BaseActivityGoodsService;
import com.ssy.lingxi.marketing.serviceimpl.base.activity.BaseActivityRecordService;
import com.ssy.lingxi.marketing.serviceimpl.base.activity.BaseActivityRuleService;
import com.ssy.lingxi.marketing.serviceimpl.base.activity.BasePlatformActivityService;
import com.ssy.lingxi.marketing.serviceimpl.component.SuitableFieldComponent;
import com.ssy.lingxi.marketing.serviceimpl.component.activity.ActivityCheckRuleComponent;
import com.ssy.lingxi.product.api.model.response.commodity.CommodityGoodsResponse;
import com.ssy.lingxi.workflow.api.model.contant.ProcessEnum;
import com.ssy.lingxi.workflow.api.model.contant.ProcessTaskStatusEnum;
import com.ssy.lingxi.workflow.api.model.vo.request.TaskExecuteVO;
import com.ssy.lingxi.workflow.api.model.vo.response.SimpleTaskCompleteVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 平台活动报名服务实现类
 * @author ds, yzc
 * @version 2.0.0
 * @date 2021/8/22
 */
@Slf4j
@Service
public class PlatformActivitySignUpServiceImpl extends BasePlatformActivityService implements IPlatformActivitySignUpService {

    @Resource
    private PlatformActivityRepository platformActivityRepository;
    @Resource
    private IProcessFeignService processFeignService;
    @Resource
    private PlatformActivitySignUpRepository signUpRepository;
    @Resource
    private ActivityGoodsRepository goodsRepository;
    @Resource
    private ActivityCheckRuleComponent activityCheckRuleComponent;
    @Resource
    private BaseActivityGoodsService activityGoodsService;
    @Resource
    private BaseActivityRuleService activityRuleService;
    @Resource
    private BaseActivityRecordService activityRecordService;

    @Override
    public Wrapper<PageData<PfActivitySignUpPageResp>> pageSummary(UserLoginCacheDTO loginUser, PfActivitySignUpPageReq pageVO) {
        PageData<PfActivitySignUpPageBO> pageList = baseActivitySingUpPage(loginUser, pageVO, pageVO.getOuterStatus(), pageVO.getInnerStatus());

        List<PfActivitySignUpPageResp> resultList = pageList.getData().stream().map(o -> {
            PfActivitySignUpPageResp resp = new PfActivitySignUpPageResp();
            resp.setId(o.getSignUpId());
            resp.setActivityId(o.getActivityId());
            resp.setActivityName(o.getActivityName());
            resp.setActivityType(o.getActivityType());
            resp.setActivityTypeName(ActivityTypeEnum.getMessage(o.getActivityType()));
            resp.setStartTime(o.getStartTime());
            resp.setEndTime(o.getEndTime());
            resp.setSignUpStartTime(o.getSignUpStartTime());
            resp.setSignUpEndTime(o.getSignUpEndTime());
            resp.setCreateTime(o.getSignUpCreateTime());

            if (PlatformActivitySignUpOuterStatusEnum.activityAftSignUpList().contains(o.getActivityOuterStatus())) {
                // platformActivityDO, [待上线活动, 活动进行, 活动终止, 活动结束, 活动取消]
                resp.setOuterStatus(o.getActivityOuterStatus());
                resp.setOuterStatusName(PlatformActivityOuterStatusEnum.getMessage(o.getActivityOuterStatus()));
            } else if (PlatformActivitySignUpOuterStatusEnum.activityPreSignUpList().contains(o.getActivityOuterStatus())) {
                // platformActivityDO, [待提交, 待报名, 待审核报名]
                if (Objects.isNull(o.getSignUpId())) {
                    // 未报名填写资料
                    resp.setOuterStatus(o.getActivityOuterStatus());
                    resp.setOuterStatusName(PlatformActivityOuterStatusEnum.getMessage(o.getActivityOuterStatus()));
                } else {
                    // 已报名填写资料
                    if (Objects.isNull(o.getSignUpOuterExtendStatus())) {
                        // 未审核
                        resp.setOuterStatus(PlatformActivitySignUpOuterStatusEnum.TO_BE_EXAMINE_SIGN_UP.getCode());
                        resp.setOuterStatusName(PlatformActivitySignUpOuterStatusEnum.TO_BE_EXAMINE_SIGN_UP.getMessage());
                    } else {
                        // 已审核
                        resp.setOuterStatus(o.getSignUpOuterExtendStatus());
                        resp.setOuterStatusName(PlatformActivitySignUpOuterStatusEnum.getMessage(o.getSignUpOuterExtendStatus()));
                    }
                }
            }

            if (Objects.isNull(o.getSignUpId())) {
                // 未填写报名资料, 默认待提交审核
                resp.setInnerStatus(PlatformActivitySignUpInnerStatusEnum.TO_BE_SUBMIT_EXAMINE.getCode());
                resp.setInnerStatusName(PlatformActivitySignUpInnerStatusEnum.TO_BE_SUBMIT_EXAMINE.getMessage());
            } else {
                // 已填写报名资料, 按状态显示
                resp.setInnerStatus(o.getSignUpInnerStatus());
                resp.setInnerStatusName(PlatformActivitySignUpInnerStatusEnum.getMessage(o.getSignUpInnerStatus()));
            }

            return resp;
        }).collect(Collectors.toList());

        return Wrapper.success(new PageData<>(pageList.getTotalCount(), resultList));
    }

    @Override
    public Wrapper<PageData<PfActivitySignUpSubmitExamPageResp>> pageByToBeSubmit(UserLoginCacheDTO loginUser, PfActivitySignUpPageReq pageVO) {
        // 平台活动外部状态为,待报名,待审核报名
        PageData<PfActivitySignUpPageBO> pageList = this.baseToBeSubmitActivitySingUpPage(loginUser, pageVO);

        List<PfActivitySignUpSubmitExamPageResp> resultList = pageList.getData().stream().map(o -> {
            PfActivitySignUpSubmitExamPageResp resp = new PfActivitySignUpSubmitExamPageResp();
            resp.setId(o.getSignUpId());
            resp.setActivityId(o.getActivityId());
            resp.setActivityName(o.getActivityName());
            resp.setActivityType(o.getActivityType());
            resp.setActivityTypeName(ActivityTypeEnum.getMessage(o.getActivityType()));
            resp.setStartTime(o.getStartTime());
            resp.setEndTime(o.getEndTime());
            resp.setSignUpStartTime(o.getSignUpStartTime());
            resp.setSignUpEndTime(o.getSignUpEndTime());
            resp.setCreateTime(o.getSignUpCreateTime());
            resp.setOuterStatus(o.getActivityOuterStatus());
            resp.setInnerStatus(o.getSignUpInnerStatus());
            resp.setOuterStatusName(PlatformActivityOuterStatusEnum.getMessage(o.getActivityOuterStatus()));
            resp.setInnerStatusName(PlatformActivitySignUpInnerStatusEnum.getMessage(o.getSignUpInnerStatus()));

            if (PlatformActivitySignUpOuterStatusEnum.activityAftSignUpList().contains(o.getActivityOuterStatus())) {
                // platformActivityDO, [待上线活动, 活动进行, 活动终止, 活动结束, 活动取消]
                resp.setOuterStatus(o.getActivityOuterStatus());
                resp.setOuterStatusName(PlatformActivityOuterStatusEnum.getMessage(o.getActivityOuterStatus()));
            } else if (PlatformActivitySignUpOuterStatusEnum.activityPreSignUpList().contains(o.getActivityOuterStatus())) {
                // platformActivityDO, [待提交, 待报名, 待审核报名]
                if (Objects.isNull(o.getSignUpId())) {
                    // 未报名填写资料
                    resp.setOuterStatus(o.getActivityOuterStatus());
                    resp.setOuterStatusName(PlatformActivityOuterStatusEnum.getMessage(o.getActivityOuterStatus()));
                } else {
                    // 已报名填写资料
                    if (Objects.isNull(o.getSignUpOuterExtendStatus())) {
                        // 未审核
                        resp.setOuterStatus(PlatformActivitySignUpOuterStatusEnum.TO_BE_EXAMINE_SIGN_UP.getCode());
                        resp.setOuterStatusName(PlatformActivitySignUpOuterStatusEnum.TO_BE_EXAMINE_SIGN_UP.getMessage());
                    } else {
                        // 已审核
                        resp.setOuterStatus(o.getSignUpOuterExtendStatus());
                        resp.setOuterStatusName(PlatformActivitySignUpOuterStatusEnum.getMessage(o.getSignUpOuterExtendStatus()));
                    }
                }
            }

            if (Objects.isNull(o.getSignUpId())) {
                // 未填写报名资料, 默认待提交审核
                resp.setInnerStatus(PlatformActivitySignUpInnerStatusEnum.TO_BE_SUBMIT_EXAMINE.getCode());
                resp.setInnerStatusName(PlatformActivitySignUpInnerStatusEnum.TO_BE_SUBMIT_EXAMINE.getMessage());
            } else {
                // 已填写报名资料, 按状态显示
                resp.setInnerStatus(o.getSignUpInnerStatus());
                resp.setInnerStatusName(PlatformActivitySignUpInnerStatusEnum.getMessage(o.getSignUpInnerStatus()));
            }

            // 填写,提交报名资料按钮
            resp.setSave(false);
            resp.setSubmit(false);
            if (Objects.isNull(resp.getId())) {
                // 未填写报名资料
                resp.setSave(true);
            } else if (PlatformActivitySignUpInnerStatusEnum.TO_BE_SUBMIT_EXAMINE.getCode().equals(resp.getInnerStatus())) {
                // 已填写报名资料
                resp.setSubmit(true);
            }

            // 修改报名资料按钮
            resp.setUpdate(false);
            if (PlatformActivitySignUpInnerStatusEnum.EXAMINE_NO_PASS_1.getCode().equals(resp.getInnerStatus())
                    || PlatformActivitySignUpInnerStatusEnum.EXAMINE_NO_PASS_2.getCode().equals(resp.getInnerStatus())) {
                // 报名内部状态审核一级不通过,审核二级不通过
                resp.setUpdate(true);
            } else if (PlatformActivitySignUpInnerStatusEnum.SUBMITTED.getCode().equals(resp.getInnerStatus())
                    && PlatformActivitySignUpOuterStatusEnum.SIGN_UP_NO_PASS.getCode().equals(resp.getOuterStatus())) {
                // 报名外部状态平台审核不通过
                resp.setUpdate(true);
            }

            return resp;
        }).collect(Collectors.toList());

        return Wrapper.success(new PageData<>(pageList.getTotalCount(), resultList));
    }

    @Override
    public Wrapper<PageData<PfActivitySignUpExamPageResp>> pageByToBeExamineStep1(UserLoginCacheDTO loginUser, PfActivitySignUpPageReq pageVO) {
        Integer outerStatus = PlatformActivitySignUpOuterStatusEnum.TO_BE_EXAMINE_SIGN_UP.getCode();
        Integer innerStatus = PlatformActivitySignUpInnerStatusEnum.TO_BE_EXAMINE_1.getCode();

        PageData<PfActivitySignUpPageBO> pageList = baseActivitySingUpPage(loginUser, pageVO, outerStatus, innerStatus);
        List<PfActivitySignUpExamPageResp> resultList = pageList.getData().stream().map(o -> {
            PfActivitySignUpExamPageResp resp = new PfActivitySignUpExamPageResp();
            resp.setId(o.getSignUpId());
            resp.setActivityId(o.getActivityId());
            resp.setActivityName(o.getActivityName());
            resp.setActivityType(o.getActivityType());
            resp.setActivityTypeName(ActivityTypeEnum.getMessage(o.getActivityType()));
            resp.setStartTime(o.getStartTime());
            resp.setEndTime(o.getEndTime());
            resp.setSignUpStartTime(o.getSignUpStartTime());
            resp.setSignUpEndTime(o.getSignUpEndTime());
            resp.setCreateTime(o.getSignUpCreateTime());
            resp.setExam(PlatformActivitySignUpInnerStatusEnum.TO_BE_EXAMINE_1.getCode().equals(o.getSignUpInnerStatus()));
            resp.setOuterStatus(o.getActivityOuterStatus());
            resp.setInnerStatus(o.getSignUpInnerStatus());
            resp.setOuterStatusName(PlatformActivityOuterStatusEnum.getMessage(o.getActivityOuterStatus()));
            resp.setInnerStatusName(PlatformActivitySignUpInnerStatusEnum.getMessage(o.getSignUpInnerStatus()));
            return resp;
        }).collect(Collectors.toList());

        return Wrapper.success(new PageData<>(pageList.getTotalCount(), resultList));
    }

    @Override
    public Wrapper<PageData<PfActivitySignUpExamPageResp>> pageByToBeExamineStep2(UserLoginCacheDTO loginUser, PfActivitySignUpPageReq pageVO) {
        Integer outerStatus = PlatformActivitySignUpOuterStatusEnum.TO_BE_EXAMINE_SIGN_UP.getCode();
        Integer innerStatus = PlatformActivitySignUpInnerStatusEnum.TO_BE_EXAMINE_2.getCode();

        PageData<PfActivitySignUpPageBO> pageList = baseActivitySingUpPage(loginUser, pageVO, outerStatus, innerStatus);
        List<PfActivitySignUpExamPageResp> resultList = pageList.getData().stream().map(o -> {
            PfActivitySignUpExamPageResp resp = new PfActivitySignUpExamPageResp();
            resp.setId(o.getSignUpId());
            resp.setActivityId(o.getActivityId());
            resp.setActivityName(o.getActivityName());
            resp.setActivityType(o.getActivityType());
            resp.setActivityTypeName(ActivityTypeEnum.getMessage(o.getActivityType()));
            resp.setStartTime(o.getStartTime());
            resp.setEndTime(o.getEndTime());
            resp.setSignUpStartTime(o.getSignUpStartTime());
            resp.setSignUpEndTime(o.getSignUpEndTime());
            resp.setCreateTime(o.getSignUpCreateTime());
            resp.setExam(PlatformActivitySignUpInnerStatusEnum.TO_BE_EXAMINE_2.getCode().equals(o.getSignUpInnerStatus()));
            resp.setOuterStatus(o.getActivityOuterStatus());
            resp.setInnerStatus(o.getSignUpInnerStatus());
            resp.setOuterStatusName(PlatformActivityOuterStatusEnum.getMessage(o.getActivityOuterStatus()));
            resp.setInnerStatusName(PlatformActivitySignUpInnerStatusEnum.getMessage(o.getSignUpInnerStatus()));
            return resp;
        }).collect(Collectors.toList());

        return Wrapper.success(new PageData<>(pageList.getTotalCount(), resultList));
    }

    @Override
    public Wrapper<PageData<PfActivitySignUpSubmitPageResp>> pageByToBeSubmitSignUp(UserLoginCacheDTO loginUser, PfActivitySignUpPageReq pageVO) {
        Integer outerStatus = PlatformActivitySignUpOuterStatusEnum.TO_BE_EXAMINE_SIGN_UP.getCode();
        Integer innerStatus = PlatformActivitySignUpInnerStatusEnum.TO_BE_SUBMIT.getCode();

        PageData<PfActivitySignUpPageBO> pageList = baseActivitySingUpPage(loginUser, pageVO, outerStatus, innerStatus);
        List<PfActivitySignUpSubmitPageResp> resultList = pageList.getData().stream().map(o -> {
            PfActivitySignUpSubmitPageResp resp = new PfActivitySignUpSubmitPageResp();
            resp.setId(o.getSignUpId());
            resp.setActivityId(o.getActivityId());
            resp.setActivityName(o.getActivityName());
            resp.setActivityType(o.getActivityType());
            resp.setActivityTypeName(ActivityTypeEnum.getMessage(o.getActivityType()));
            resp.setStartTime(o.getStartTime());
            resp.setEndTime(o.getEndTime());
            resp.setSignUpStartTime(o.getSignUpStartTime());
            resp.setSignUpEndTime(o.getSignUpEndTime());
            resp.setCreateTime(o.getSignUpCreateTime());
            resp.setSubmit(PlatformActivitySignUpInnerStatusEnum.TO_BE_SUBMIT.getCode().equals(o.getSignUpInnerStatus()));
            resp.setOuterStatus(o.getActivityOuterStatus());
            resp.setInnerStatus(o.getSignUpInnerStatus());
            resp.setOuterStatusName(PlatformActivityOuterStatusEnum.getMessage(o.getActivityOuterStatus()));
            resp.setInnerStatusName(PlatformActivitySignUpInnerStatusEnum.getMessage(o.getSignUpInnerStatus()));
            return resp;
        }).collect(Collectors.toList());

        return Wrapper.success(new PageData<>(pageList.getTotalCount(), resultList));
    }

    @Override
    public Wrapper<PfActivitySignUpDetailResp> detail(UserLoginCacheDTO loginUser, Long id) {
        PlatformActivityDO platformActivityDO = platformActivityRepository.findById(id).orElse(null);
        if (Objects.isNull(platformActivityDO)) {
            return Wrapper.fail(ResponseCode.MARKETING_ACTIVITY_NOT_EXISTS);
        }

        PfActivitySignUpDetailResp detailResp = new PfActivitySignUpDetailResp();
        detailResp.setId(platformActivityDO.getId());
        detailResp.setActivityName(platformActivityDO.getActivityName());
        detailResp.setOuterStatus(platformActivityDO.getOuterStatus());
        detailResp.setActivityType(platformActivityDO.getActivityType());
        detailResp.setActivityTypeName(ActivityTypeEnum.getMessage(platformActivityDO.getActivityType()));
        detailResp.setStartTime(platformActivityDO.getStartTime());
        detailResp.setEndTime(platformActivityDO.getEndTime());
        detailResp.setActivitySignUpTypeName(ActivitySignUpTypeEnum.getMessage(platformActivityDO.getActivitySignUpType()));
        detailResp.setSignUpStartTime(platformActivityDO.getSignUpStartTime());
        detailResp.setSignUpEndTime(platformActivityDO.getSignUpEndTime());
        detailResp.setActivityDefined(getActivityDefine(BelongTypeEnum.PLATFORM, platformActivityDO.getActivityType(), platformActivityDO.getActivityDefined()));
        detailResp.setEnterpriseMember(SuitableFieldComponent.parseActivitySuitableMemberType(platformActivityDO.getSuitableMemberType(), SuitableFieldComponent.pf_merchant_type_loc));
        detailResp.setPersonalMember(SuitableFieldComponent.parseActivitySuitableMemberType(platformActivityDO.getSuitableMemberType(),  SuitableFieldComponent.pf_merchant_personal_type_loc));
        detailResp.setNewMember(SuitableFieldComponent.parseActivitySuitableMember(platformActivityDO.getSuitableMember(), SuitableFieldComponent.pf_new_member_loc));
        detailResp.setOldMember(SuitableFieldComponent.parseActivitySuitableMember(platformActivityDO.getSuitableMember(), SuitableFieldComponent.pf_ole_member_loc));

        // 适用会员等级
        List<ActivityMemberLevelResp> memberLevelRespList = activityRuleService.listMemberLevel(BelongTypeEnum.PLATFORM, platformActivityDO.getId());
        detailResp.setMemberLevelList(memberLevelRespList);

        // 适用商城
        List<ActivityShopResp> shopRespList = activityRuleService.listShop(BelongTypeEnum.PLATFORM, platformActivityDO.getId());
        detailResp.setShopList(shopRespList);

        // 查询是否已经报名
        PlatformActivitySignUpDO signUpDO = signUpRepository.findByPlatformActivityIdAndMemberIdAndRoleId(id, loginUser.getMemberId(), loginUser.getMemberRoleId());
        if (Objects.isNull(signUpDO)) {
            // 商家未报名
            // 内部状态
            detailResp.setInnerStatus(PlatformActivitySignUpInnerStatusEnum.TO_BE_SUBMIT_EXAMINE.getCode());
            detailResp.setInnerStatusName(PlatformActivitySignUpInnerStatusEnum.TO_BE_SUBMIT_EXAMINE.getMessage());

            // 外部状态
            detailResp.setOuterStatus(platformActivityDO.getOuterStatus());
            detailResp.setOuterStatusName(PlatformActivitySignUpOuterStatusEnum.getMessage(detailResp.getOuterStatus()));

            // 获取内部流转步骤
            List<TaskStepVO> innerTaskStepVOS = processFeignService.listTaskStep(ProcessEnum.PLATFORM_ACTIVITY_SIGN_UP_INNER_VERIFY.getProcessKey(), null, loginUser.getMemberId());
            detailResp.setInnerTaskStepList(innerTaskStepVOS);

            // 封装内部流转记录
            detailResp.setInnerRecordDOList(Collections.emptyList());

            // 获取外部流转步骤
            List<TaskStepVO> outTaskStepVOS = processFeignService.listTaskStepOut(platformActivityDO.getOuterProcessKey(), platformActivityDO.getOuterTaskId(), null, loginUser.getMemberId());
            detailResp.setOuterTaskStepList(outTaskStepVOS);

            // 封装外部流转记录
            List<ActivityOuterRecordResp> platformOuterRecord = activityRecordService.getPlatformOuterRecord(loginUser, platformActivityDO.getId());
            detailResp.setOuterRecordDOList(platformOuterRecord);
        } else {
            // 商家已报名
            // 内部状态
            detailResp.setInnerStatus(signUpDO.getStatus());
            detailResp.setInnerStatusName(PlatformActivitySignUpInnerStatusEnum.getMessage(signUpDO.getStatus()));

            // 外部状态
            Integer outerExtendStatus = signUpDO.getOuterExtendStatus();
            // 如果待报名审核[存在一对多状态,会员审核被驳回]
            if (platformActivityDO.getOuterStatus().equals(PlatformActivityOuterStatusEnum.TO_BE_EXAMINE_SIGN_UP.getCode()) && outerExtendStatus != null && outerExtendStatus > 0) {
                detailResp.setOuterStatus(outerExtendStatus);
                detailResp.setOuterStatusName(PlatformActivitySignUpOuterStatusEnum.getMessage(outerExtendStatus));
            } else {
                detailResp.setOuterStatus(platformActivityDO.getOuterStatus());
                detailResp.setOuterStatusName(PlatformActivityOuterStatusEnum.getMessage(platformActivityDO.getOuterStatus()));
            }

            // 获取内部流转步骤
            List<TaskStepVO> innerTaskStepVOS = processFeignService.listTaskStep(signUpDO.getProcessKey(), signUpDO.getTaskId(), signUpDO.getMemberId());
            detailResp.setInnerTaskStepList(innerTaskStepVOS);

            // 封装内部流转记录
            List<ActivityInnerRecordResp> platformInnerRecord = activityRecordService.getPlatformSignUpInnerRecord(loginUser, signUpDO.getId());
            detailResp.setInnerRecordDOList(platformInnerRecord);

            // 获取外部流转步骤
            List<TaskStepVO> outTaskStepVOS = processFeignService.listTaskStepOut(platformActivityDO.getOuterProcessKey(), platformActivityDO.getOuterTaskId(), null, loginUser.getMemberId());
            detailResp.setOuterTaskStepList(outTaskStepVOS);

            // 封装外部流转记录
            List<ActivityOuterRecordResp> platformOuterRecord = activityRecordService.getPlatformSignUpOuterRecord(loginUser, platformActivityDO.getId(), signUpDO.getId());
            detailResp.setOuterRecordDOList(platformOuterRecord);
        }

        //根据当前活动获取要过滤的skuId
        Set<Long> filterSkuId = activityCheckRuleComponent.getFilterSkuId(
                platformActivityDO.getActivityType(),
                platformActivityDO.getActivityDefined(),
                platformActivityDO.getStartTime(),
                platformActivityDO.getEndTime()
        );
        detailResp.setFilterSkuId(filterSkuId);

        return Wrapper.success(detailResp);
    }

    @Override
    public Wrapper<PageData<PfActivitySignUpGoodsPageResp>> pageByActivityGoods(UserLoginCacheDTO loginUser, PfActivitySignUpGoodsPageReq pageVO) {
        // 会员进行查询, 传入memberId, roleId
        return activityGoodsService.basePageSignUpActivityGoods(loginUser.getMemberId(), loginUser.getMemberRoleId(), pageVO.getSignUpId(), pageVO.getCurrent(), pageVO.getPageSize());
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Wrapper<Void> save(UserLoginCacheDTO loginUser, PfActivitySignUpAddReq request) {
        long currentTimeMillis = System.currentTimeMillis();

        // 平台活动不支持渠道会员
        if (!this.checkMemberSupport(loginUser)) {
            return Wrapper.success();
        }

        PlatformActivityDO platformActivityDO = platformActivityRepository.findById(request.getActivityId()).orElse(null);
        if (Objects.isNull(platformActivityDO)) {
            return Wrapper.fail(ResponseCode.MARKETING_ACTIVITY_NOT_EXISTS);
        }

        // 校验活动状态
        if (!PlatformActivityOuterStatusEnum.TO_BE_EXAMINE_SIGN_UP.getCode().equals(platformActivityDO.getOuterStatus())) {
            return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_SIGN_UP_NOT_ALLOW);
        }

        // 校验报名时间
        if (platformActivityDO.getSignUpStartTime() > currentTimeMillis || platformActivityDO.getSignUpEndTime() < currentTimeMillis) {
            return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_SIGN_UP_TIME_NOT_ALLOW);
        }

        // 只有商家活动才可报名
        if (!ActivitySignUpTypeEnum.SUPPLIER.getCode().equals(platformActivityDO.getActivitySignUpType())) {
            return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_TYPE_NOT_ALLOW);
        }

        // 指定邀请会员报名
        if (CommonBooleanEnum.NO.getCode().equals(platformActivityDO.getInviteType())) {
            Set<PlatformActivityInviteDO> inviteMembers = platformActivityDO.getInviteMembers();
            if (inviteMembers.stream().noneMatch(inviteMember -> inviteMember.getMemberId().equals(loginUser.getMemberId()) && inviteMember.getRoleId().equals(loginUser.getMemberRoleId()))) {
                return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_NOT_IN_INVITE);
            }
        }

        // 校验重复报名
        PlatformActivitySignUpDO dbSignUpDO = signUpRepository.findByPlatformActivityIdAndMemberIdAndRoleId(request.getActivityId(), loginUser.getMemberId(), loginUser.getMemberRoleId());
        if (Objects.nonNull(dbSignUpDO)) {
            return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_SIGN_UP_IS_REPEAT);
        }

        // 校验活动商品
        Wrapper<Void> checkGoodsWrapper = activityGoodsService.checkActivityGoods(platformActivityDO.getActivityType(), platformActivityDO.getActivityDefined(), request.getProductList());
        if (ResponseCode.SUCCESS.getCode() != checkGoodsWrapper.getCode()) {
            return checkGoodsWrapper;
        }

        // 商品叠加活动校验
        Set<Long> filterSkuId = activityCheckRuleComponent.getFilterSkuId(platformActivityDO.getActivityType(), platformActivityDO.getActivityDefined(), platformActivityDO.getStartTime(), platformActivityDO.getEndTime());
        if (request.getProductList().stream().anyMatch(e -> filterSkuId.contains(e.getSkuId()))) {
            return Wrapper.fail(ResponseCode.MARKETING_ACTIVITY_GOODS_SUPERPOSITION);
        }
        //查询商品skuList
        Map<Long, CommodityGoodsResponse> skuMap = activityGoodsService.getReqSkuMap(request.getProductList(),platformActivityDO.getActivityType(),loginUser.getMemberId(),loginUser.getMemberRoleId());
        if(skuMap==null){
            return Wrapper.fail(ResponseCode.MARKETING_ACTIVITY_GOODS_SKU_NOT_EXISTS_ERROR);
        }
        // 会员报名
        PlatformActivitySignUpDO signUpDO = new PlatformActivitySignUpDO();
        signUpDO.setCreateTime(currentTimeMillis);
        signUpDO.setUpdateTime(currentTimeMillis);
        signUpDO.setMemberId(loginUser.getMemberId());
        signUpDO.setMemberName(loginUser.getCompany());
        signUpDO.setRoleId(loginUser.getMemberRoleId());
        signUpDO.setPlatformActivity(platformActivityDO);
        signUpDO.setProcessKey(ProcessEnum.PLATFORM_ACTIVITY_SIGN_UP_INNER_VERIFY.getProcessKey());
        signUpRepository.saveAndFlush(signUpDO);

        // 保存平台活动商品
        activityGoodsService.savePlatformSignUpActivityGoods(loginUser, platformActivityDO.getId(), platformActivityDO.getActivityType(), platformActivityDO.getActivityDefined(), signUpDO.getId(), request.getProductList(),skuMap);

        // 启动内部工作流
        SimpleTaskCompleteVO simpleTaskCompleteVO = processFeignService.startSimpleProcess(loginUser.getMemberId(), loginUser.getMemberRoleId(),
                signUpDO.getProcessKey(), signUpDO.getId());
        signUpDO.setStatus(simpleTaskCompleteVO.getStatus());
        signUpDO.setTaskId(simpleTaskCompleteVO.getTaskId());
        signUpRepository.saveAndFlush(signUpDO);

        // 内部工作流日志
        activityRecordService.savePlatformActivitySignUpInnerRecord(loginUser, platformActivityDO.getId(), signUpDO.getId(), signUpDO.getStatus(),
                PlatformActivitySignUpInnerStatusEnum.getMessage(signUpDO.getStatus()), ActivityStrOperateEnum.pt_inner_signup_save.getMessage(), "");

        return Wrapper.success();
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Wrapper<Void> update(UserLoginCacheDTO loginUser, PfActivitySignUpUpdateReq request) {
        long currentTimeMillis = System.currentTimeMillis();

        // 平台活动不支持渠道会员
        if (!this.checkMemberSupport(loginUser)) {
            return Wrapper.success();
        }

        PlatformActivityDO platformActivityDO = platformActivityRepository.findById(request.getActivityId()).orElse(null);
        if (Objects.isNull(platformActivityDO)) {
            return Wrapper.fail(ResponseCode.MARKETING_ACTIVITY_NOT_EXISTS);
        }

        // 校验活动状态
        if (!PlatformActivityOuterStatusEnum.TO_BE_EXAMINE_SIGN_UP.getCode().equals(platformActivityDO.getOuterStatus())) {
            return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_SIGN_UP_NOT_ALLOW);
        }

        // 校验报名时间
        if (platformActivityDO.getSignUpStartTime() > currentTimeMillis || platformActivityDO.getSignUpEndTime() < currentTimeMillis) {
            return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_SIGN_UP_TIME_NOT_ALLOW);
        }

        // 只有商家活动才可报名
        if (!ActivitySignUpTypeEnum.SUPPLIER.getCode().equals(platformActivityDO.getActivitySignUpType())) {
            return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_TYPE_NOT_ALLOW);
        }

        // 指定邀请会员报名
        if (CommonBooleanEnum.NO.getCode().equals(platformActivityDO.getInviteType())) {
            Set<PlatformActivityInviteDO> inviteMembers = platformActivityDO.getInviteMembers();
            if (inviteMembers.stream().noneMatch(inviteMember -> inviteMember.getMemberId().equals(loginUser.getMemberId()) && inviteMember.getRoleId().equals(loginUser.getMemberRoleId()))) {
                return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_NOT_IN_INVITE);
            }
        }

        // 校验重复报名
        PlatformActivitySignUpDO dbSignUpDO = signUpRepository.findByPlatformActivityIdAndMemberIdAndRoleId(request.getActivityId(), loginUser.getMemberId(), loginUser.getMemberRoleId());
        if (Objects.isNull(dbSignUpDO)) {
            return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_SIGN_UP_IS_REPEAT);
        }

        // 校验活动商品
        Wrapper<Void> checkGoodsWrapper = activityGoodsService.checkActivityGoods(platformActivityDO.getActivityType(), platformActivityDO.getActivityDefined(), request.getProductList());
        if (ResponseCode.SUCCESS.getCode() != checkGoodsWrapper.getCode()) {
            return checkGoodsWrapper;
        }

        // 商品叠加活动校验
        Set<Long> filterSkuId = activityCheckRuleComponent.getFilterSkuId(platformActivityDO.getActivityType(), platformActivityDO.getActivityDefined(), platformActivityDO.getStartTime(), platformActivityDO.getEndTime());
        // 除去当前记录更新之前的数据
        Set<Long> goodsSkuIds = goodsRepository.findByBelongTypeAndActivityId(BelongTypeEnum.PLATFORM.getCode(), platformActivityDO.getId()).stream().map(ActivityGoodsDO::getSkuId).collect(Collectors.toSet());
        filterSkuId.removeAll(goodsSkuIds);
        if (request.getProductList().stream().anyMatch(e -> filterSkuId.contains(e.getSkuId()))) {
            return Wrapper.fail(ResponseCode.MARKETING_ACTIVITY_GOODS_SUPERPOSITION);
        }

        PlatformActivitySignUpDO signUpDO = signUpRepository.findByIdAndMemberIdAndRoleId(request.getId(), loginUser.getMemberId(), loginUser.getMemberRoleId());
        if (Objects.isNull(signUpDO)) {
            return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_SIGN_UP_NOT_EXISTS);
        }

        signUpDO.setUpdateTime(currentTimeMillis);

        // 是否可修改
        List<Integer> statusList = Arrays.asList(PlatformActivitySignUpInnerStatusEnum.TO_BE_SUBMIT_EXAMINE.getCode(),
                PlatformActivitySignUpInnerStatusEnum.EXAMINE_NO_PASS_1.getCode(),
                PlatformActivitySignUpInnerStatusEnum.EXAMINE_NO_PASS_2.getCode(),
                PlatformActivitySignUpOuterStatusEnum.SIGN_UP_NO_PASS.getCode()
        );
        boolean canUpdateFlag = statusList.contains(signUpDO.getStatus()) || PlatformActivitySignUpOuterStatusEnum.SIGN_UP_NO_PASS.getCode().equals(signUpDO.getOuterExtendStatus());
        if (!canUpdateFlag) {
            return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_SIGN_UP_NOT_ALLOW_UPDATE);
        }
        //查询商品skuList
        Map<Long, CommodityGoodsResponse> skuMap = activityGoodsService.getReqSkuMap(request.getProductList(),platformActivityDO.getActivityType(),loginUser.getMemberId(),loginUser.getMemberRoleId());
        if(skuMap==null){
            return Wrapper.fail(ResponseCode.MARKETING_ACTIVITY_GOODS_SKU_NOT_EXISTS_ERROR);
        }
        // 平台活动商品
        activityGoodsService.deleteSignUpActivityGoods(platformActivityDO, dbSignUpDO.getId());
        activityGoodsService.savePlatformSignUpActivityGoods(loginUser, platformActivityDO.getId(), platformActivityDO.getActivityType(), platformActivityDO.getActivityDefined(), signUpDO.getId(), request.getProductList(),skuMap);

        // 启动内部工作流
        SimpleTaskCompleteVO simpleTaskCompleteVO = processFeignService.startSimpleProcess(loginUser.getMemberId(), loginUser.getMemberRoleId(),
                signUpDO.getProcessKey(), signUpDO.getId());
        signUpDO.setStatus(simpleTaskCompleteVO.getStatus());
        // 清除平台审核的状态
        signUpDO.setOuterExtendStatus(null);
        signUpDO.setTaskId(simpleTaskCompleteVO.getTaskId());
        signUpRepository.saveAndFlush(signUpDO);

        //内部工作流日志
        activityRecordService.savePlatformActivitySignUpInnerRecord(loginUser, platformActivityDO.getId(), signUpDO.getId(), signUpDO.getStatus(), PlatformActivitySignUpInnerStatusEnum.getMessage(signUpDO.getStatus()), ActivityStrOperateEnum.pt_inner_signup_update.getMessage(), "");

        return Wrapper.success();
    }

    @Override
    public Wrapper<FilterSkuIdResponse> getFilterSkuId(UserLoginCacheDTO loginUser, FilterSkuIdRequest request) {
        Set<Long> skuIds = activityCheckRuleComponent.getFilterSkuIdByJsonObj(request.getActivityType(), request.getActivityDefined(), request.getStartTime(), request.getEndTime());

        FilterSkuIdResponse response = new FilterSkuIdResponse();
        response.setFilterSkuId(skuIds);
        return Wrapper.success(response);
    }

    @Override
    public Wrapper<Void> submitExamine(UserLoginCacheDTO loginUser, PfActivityExamineSubmitReq submitReq) {
        // 校验
        PlatformActivitySignUpDO signUpDO = signUpRepository.findByIdAndMemberIdAndRoleId(submitReq.getId(), loginUser.getMemberId(), loginUser.getMemberRoleId());
        if (Objects.isNull(signUpDO)) {
            return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_SIGN_UP_RECORD_IS_NOT_EXISTS);
        }

        PlatformActivityDO platformActivity = signUpDO.getPlatformActivity();
        if (Objects.isNull(platformActivity)) {
            return Wrapper.fail(ResponseCode.MARKETING_ACTIVITY_NOT_EXISTS);
        }

        if (!PlatformActivitySignUpInnerStatusEnum.TO_BE_SUBMIT_EXAMINE.getCode().equals(signUpDO.getStatus())) {
            return Wrapper.fail(ResponseCode.MARKETING_ACTIVITY_CURRENT_STATUS_NOT_ALLOW_UPDATE);
        }

        // 执行内部工作流
        TaskExecuteVO taskStartVO = new TaskExecuteVO();
        taskStartVO.setProcessKey(signUpDO.getProcessKey());
        taskStartVO.setMemberId(MemberRoleEnum.PLATFORM.getMemberId());
        taskStartVO.setRoleId(MemberRoleEnum.PLATFORM.getRoleId());
        taskStartVO.setDataId(signUpDO.getId());
        taskStartVO.setAgree(ProcessTaskStatusEnum.GOTO_NEXT_STEP.getCode());
        taskStartVO.setTaskId(signUpDO.getTaskId());
        Wrapper<SimpleTaskCompleteVO> taskResult = processFeignService.completeSimpleTask(taskStartVO);
        if (ResponseCode.SUCCESS.getCode() != taskResult.getCode()) {
            throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
        }
        signUpDO.setTaskId(taskResult.getData().getTaskId());
        signUpDO.setStatus(taskResult.getData().getStatus());
        signUpDO.setUpdateTime(System.currentTimeMillis());
        signUpRepository.saveAndFlush(signUpDO);

        // 内部流程记录
        activityRecordService.savePlatformActivitySignUpInnerRecord(loginUser, platformActivity.getId(), signUpDO.getId(), taskResult.getData().getStatus(),
                PlatformActivitySignUpInnerStatusEnum.getMessage(signUpDO.getStatus()), ActivityStrOperateEnum.pt_inner_signup_submit.getMessage(), "");
        return Wrapper.success();
    }

    @Override
    public Wrapper<Void> submitExamineBatch(UserLoginCacheDTO loginUser, PfActivitySingUpIdsReq req) {
        // 校验
        List<PlatformActivitySignUpDO> signUpDOList = signUpRepository.findByIdInAndMemberIdAndRoleId(req.getIds(), loginUser.getMemberId(), loginUser.getMemberRoleId());
        if (CollectionUtils.isEmpty(signUpDOList)) {
            return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_SIGN_UP_RECORD_IS_NOT_EXISTS);
        }

        // 批量审核状态为待提交的数据
        List<PlatformActivitySignUpDO> updateList = new ArrayList<>();
        for (PlatformActivitySignUpDO signUpDO : signUpDOList) {
            if (!PlatformActivitySignUpInnerStatusEnum.TO_BE_SUBMIT_EXAMINE.getCode().equals(signUpDO.getStatus())) {
                continue;
            }
            updateList.add(signUpDO);
        }

        for (PlatformActivitySignUpDO signUpDO : updateList) {
            // 执行内部工作流
            TaskExecuteVO taskStartVO = new TaskExecuteVO();
            taskStartVO.setProcessKey(signUpDO.getProcessKey());
            taskStartVO.setMemberId(MemberRoleEnum.PLATFORM.getMemberId());
            taskStartVO.setRoleId(MemberRoleEnum.PLATFORM.getRoleId());
            taskStartVO.setDataId(signUpDO.getId());
            taskStartVO.setAgree(ProcessTaskStatusEnum.GOTO_NEXT_STEP.getCode());
            taskStartVO.setTaskId(signUpDO.getTaskId());
            Wrapper<SimpleTaskCompleteVO> taskResult = processFeignService.completeSimpleTask(taskStartVO);
            if (ResponseCode.SUCCESS.getCode() != taskResult.getCode()) {
                throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
            }
            signUpDO.setTaskId(taskResult.getData().getTaskId());
            signUpDO.setStatus(taskResult.getData().getStatus());
            signUpDO.setUpdateTime(System.currentTimeMillis());
            signUpRepository.saveAndFlush(signUpDO);

            //内部流程记录
            activityRecordService.savePlatformActivitySignUpInnerRecord(loginUser, signUpDO.getPlatformActivity().getId(), signUpDO.getId(), taskResult.getData().getStatus(),
                    PlatformActivitySignUpInnerStatusEnum.getMessage(signUpDO.getStatus()), ActivityStrOperateEnum.pt_inner_signup_submit.getMessage(), "");
        }

        return Wrapper.success();
    }

    @Override
    public Wrapper<Void> examineStep1(UserLoginCacheDTO loginUser, PfActivityExamineSignUpReq req) {
        // 校验
        PlatformActivitySignUpDO signUpDO = signUpRepository.findByIdAndMemberIdAndRoleId(req.getId(), loginUser.getMemberId(), loginUser.getMemberRoleId());
        if (Objects.isNull(signUpDO)) {
            return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_SIGN_UP_RECORD_IS_NOT_EXISTS);
        }

        if (!PlatformActivitySignUpInnerStatusEnum.TO_BE_EXAMINE_1.getCode().equals(signUpDO.getStatus())) {
            return Wrapper.fail(ResponseCode.MARKETING_ACTIVITY_CURRENT_STATUS_NOT_ALLOW_UPDATE);
        }

        this.baseExamineStep1(loginUser, Collections.singletonList(signUpDO), req.getAgree(), req.getReason());
        return Wrapper.success();
    }

    @Override
    public Wrapper<Void> examineStep1batch(UserLoginCacheDTO loginUser, PfActivitySingUpIdsReq req) {
        // 校验
        List<PlatformActivitySignUpDO> signUpDOList = signUpRepository.findByIdInAndMemberIdAndRoleId(req.getIds(), loginUser.getMemberId(), loginUser.getMemberRoleId());
        if (CollectionUtils.isEmpty(signUpDOList)) {
            return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_SIGN_UP_RECORD_IS_NOT_EXISTS);
        }

        for (PlatformActivitySignUpDO signUpDO : signUpDOList) {
            if (!PlatformActivitySignUpInnerStatusEnum.TO_BE_EXAMINE_1.getCode().equals(signUpDO.getStatus())) {
                return Wrapper.fail(ResponseCode.MARKETING_ACTIVITY_CURRENT_STATUS_NOT_ALLOW_UPDATE);
            }
        }

        this.baseExamineStep1(loginUser, signUpDOList, ProcessTaskStatusEnum.AGREE.getCode(), "");
        return Wrapper.success();
    }

    @Override
    public Wrapper<Void> examineStep2(UserLoginCacheDTO loginUser, PfActivityExamineSignUpReq req) {
        // 校验
        PlatformActivitySignUpDO signUpDO = signUpRepository.findByIdAndMemberIdAndRoleId(req.getId(), loginUser.getMemberId(), loginUser.getMemberRoleId());
        if (Objects.isNull(signUpDO)) {
            return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_SIGN_UP_RECORD_IS_NOT_EXISTS);
        }

        if (!PlatformActivitySignUpInnerStatusEnum.TO_BE_EXAMINE_2.getCode().equals(signUpDO.getStatus())) {
            return Wrapper.fail(ResponseCode.MARKETING_ACTIVITY_CURRENT_STATUS_NOT_ALLOW_UPDATE);
        }

        this.baseExamineStep2(loginUser, Collections.singletonList(signUpDO), req.getAgree(), req.getReason());
        return Wrapper.success();
    }

    @Override
    public Wrapper<Void> examineStep2batch(UserLoginCacheDTO loginUser, PfActivitySingUpIdsReq req) {
        // 校验
        List<PlatformActivitySignUpDO> signUpDOList = signUpRepository.findByIdInAndMemberIdAndRoleId(req.getIds(), loginUser.getMemberId(), loginUser.getMemberRoleId());
        if (CollectionUtils.isEmpty(signUpDOList)) {
            return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_SIGN_UP_RECORD_IS_NOT_EXISTS);
        }

        for (PlatformActivitySignUpDO signUpDO : signUpDOList) {
            if (!PlatformActivitySignUpInnerStatusEnum.TO_BE_EXAMINE_2.getCode().equals(signUpDO.getStatus())) {
                return Wrapper.fail(ResponseCode.MARKETING_ACTIVITY_CURRENT_STATUS_NOT_ALLOW_UPDATE);
            }
        }

        this.baseExamineStep2(loginUser, signUpDOList, ProcessTaskStatusEnum.AGREE.getCode(), "");
        return Wrapper.success();
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Wrapper<Void> submitSignUp(UserLoginCacheDTO loginUser, Long id) {
        // 校验
        PlatformActivitySignUpDO signUpDO = signUpRepository.findByIdAndMemberIdAndRoleId(id, loginUser.getMemberId(), loginUser.getMemberRoleId());
        if (Objects.isNull(signUpDO)) {
            return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_SIGN_UP_RECORD_IS_NOT_EXISTS);
        }

        if (!PlatformActivitySignUpInnerStatusEnum.TO_BE_SUBMIT.getCode().equals(signUpDO.getStatus())) {
            return Wrapper.fail(ResponseCode.MARKETING_ACTIVITY_CURRENT_STATUS_NOT_ALLOW_UPDATE);
        }

        PlatformActivityDO platformActivity = signUpDO.getPlatformActivity();
        if (Objects.isNull(platformActivity)) {
            return Wrapper.fail(ResponseCode.MARKETING_RECORDS_DONT_EXIST);
        }

        if (platformActivity.getEndTime() <= System.currentTimeMillis()) {
            return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_SIGN_UP_TIME_HAS_TO);
        }

        this.baseSubmitSignUp(loginUser, Collections.singletonList(signUpDO));
        return Wrapper.success();
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Wrapper<Void> submitSignUpBatch(UserLoginCacheDTO loginUser, List<Long> idList) {
        // 校验
        List<PlatformActivitySignUpDO> signUpDOList = signUpRepository.findByIdInAndMemberIdAndRoleId(idList, loginUser.getMemberId(), loginUser.getMemberRoleId());
        if (CollectionUtils.isEmpty(signUpDOList)) {
            return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_SIGN_UP_RECORD_IS_NOT_EXISTS);
        }

        for (PlatformActivitySignUpDO signUpDO : signUpDOList) {
            if (!PlatformActivitySignUpInnerStatusEnum.TO_BE_SUBMIT.getCode().equals(signUpDO.getStatus())) {
                return Wrapper.fail(ResponseCode.MARKETING_ACTIVITY_CURRENT_STATUS_NOT_ALLOW_UPDATE);
            }

            PlatformActivityDO platformActivity = signUpDO.getPlatformActivity();
            if (Objects.isNull(platformActivity)) {
                return Wrapper.fail(ResponseCode.MARKETING_RECORDS_DONT_EXIST);
            }

            if (platformActivity.getEndTime() <= System.currentTimeMillis()) {
                return Wrapper.fail(ResponseCode.MARKETING_PLATFORM_ACTIVITY_SIGN_UP_TIME_HAS_TO);
            }
        }

        this.baseSubmitSignUp(loginUser, signUpDOList);
        return Wrapper.success();
    }

    @Override
    public PageData<PfActivitySignUpPageBO> pageExecuteByMerchant(UserLoginCacheDTO loginUser, PfActivitySignUpPageReq pageVO) {
        return pageExecuteByMerchant(loginUser,pageVO,pageVO.getOuterStatus());
    }
}
